package LeetCode;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}14:11
 */
public class LeetCode53 {

    public static void main(String[] args) {
        int[] arr = {-10,-5,-6,-8,-9,-1};
        System.out.println(new LeetCode53().maxSubArray(arr));
    }

    public int maxSubArray(int[] nums) {
        int result = nums[0];
        for (int i = 1; i < nums.length; i++){
            if (nums[i-1] > 0){
                nums[i] += nums[i-1];
            }
            result = Math.max(result,nums[i]);
        }
        return result;
    }
}
